<template>
  <div>
    <el-dialog title="销售详情" :visible.sync="dialogPurchaseOrderDetailFormVisible"   width="65%">

      <!--      <div style="float: left;margin-top: 8px;margin-bottom: 8px">-->
      <!--        <el-button type="primary" @click="_add">添加</el-button>-->
      <!--      </div>-->

      <div style="margin-top: 20px">
        <el-table
          :data="getPage"
          border
          height="400"
          style="width: 100%">
          <el-table-column v-for="item in columnName" :key="item.id" :label="item.label" >
            <template slot-scope="scope">
              <span>{{scope.row[item.prop]}}</span>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 20, 40]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>


      </div>

    </el-dialog>
  </div>


</template>

<script>
  export default {
    components:{
    },
    mounted(){
    },

    name: "PurchaseOrderDetail",
    data(){
      return{
        currentPage:1, //初始页
        pageSize:10,    //    每页的数据
        total:0,    //    每页的数据
        getPage:[],

        salesId:'',
        columnName:[
          {prop:"productName",label:"商品名称",width:"120",fixed:true},
          {prop:"categoryName",label:"类别",width:"120"},
          {prop:"supplier",label:"供应商",width:"120"},
          {prop:"price",label:"单价",width:"120"},
          {prop:"num",label:"购买数量",width:"120"},
          {prop:"uname",label:"销售人员",width:"120"},
          {prop:"remark",label:"备注",width:"120"},
        ],

        pNameList:[],
        parentName: '',

        dialogPurchaseOrderDetailFormVisible: false,

        formLabelWidth: '120px'
      }
    },
    methods:{
      _add(){

        this.$refs.sysUserSelectRef._open();
      },
      _open(id){
        this.salesId=id;
        this.dialogPurchaseOrderDetailFormVisible=true;
        this._page();
      },

      _remove(id){
        this.$confirm('是否删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'info'
        }).then(() => {

          this.$http.delete('/sys_role_rel_user/delete?id='+id).then(res=>{
            this._page();
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }).catch(err=>{

          })
        }).catch(() => {

        });
      },


      _userSelected(user){
        let data={roleId:this.roleId,userId:user.id};
        this.$http.post('/sys_role_rel_user/add',data).then(res=>{
          this._page();
          this.$message({
            type: 'success',
            message: '添加成功!'
          });


        }).catch(err=>{
          this.$message({
            type: 'info',
            message: '添加失败'
          });
        })
      },
      handleSizeChange(val) {
        this.pageSize=val;
        this._page();
      },
      handleCurrentChange(val) {
        this.currentPage=val;
        this._page();
      },


      _page(){
        this.$http.post('/t_sales_item/page_vo?rows='+this.pageSize+'&page='+this.currentPage,{salesId:this.salesId}).then(res=>{
          let data= res.data.data;
          this.getPage=data.records;
          console.log('----------------data',data)
          console.log('-----------------',data.total)
          this.total=data.total;
        }).catch(err=>{
          console.log(err)
        });
      },

      _pNameChange(data){
        this.form.pid=data;
      },

      _listParent(){
        this.$http.get('/api/base/sys_role/list_parent').then(res=>{
          this.pNameList=res.data.data;
        }).catch(err=>{

        });
      },


      _ok(){
        let userData= this.form;
        if (undefined === userData.id){
          this.$http.post('/sys_role/add',userData).then(res=>{
            this.$message({
              type: 'success',
              message: '添加成功!'
            });
            this.$emit('on-result-change')
            this.dialogFormVisible = false;

          }).catch(err=>{
            this.$message({
              type: 'info',
              message: '添加失败'
            });
          })

        } else {
          this.$http.put('/sys_role/'+userData.id,userData).then(res=>{
            this.$message({
              type: 'success',
              message: '编辑成功!'
            });
            this.$emit('on-result-change')
            this.dialogFormVisible = false;

          }).catch(err=>{
            this.$message({
              type: 'info',
              message: '编辑失败'
            });
          })
        }




      }

    },
  }
</script>

<style scoped>

</style>
